<h2>Agregar Pre Registro</h2>

<%= form_for(@cultural_heritage_pre_register, :url=>{:action=>"process_step_pre_register"}, :html=>{:multipart=>true,:onsubmit => "return validate(this);" }) do |f| %>
  <% if @cultural_heritage_pre_register.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@cultural_heritage_pre_register.errors.count, "error") %> prohibited this cultural_heritage_pre_register_request from being saved:</h2>

      <ul>
      <% @cultural_heritage_pre_register.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
  <!-- Guardamos los valores hidden de la solicitud de pre-registro: Step1-->
  <%= fields_for @cultural_heritage_pre_register_request do |pre_register_request_form| %>
    <% if @cultural_heritage_pre_register_request.id.to_i > 0 %>
      <%= hidden_field_tag "request_pre_register_id",@cultural_heritage_pre_register_request.id %>
    <% end %>
    <%= pre_register_request_form.hidden_field :state %>
    <%= pre_register_request_form.hidden_field :send_date %>
    <%= pre_register_request_form.hidden_field :description %>
    <%= pre_register_request_form.hidden_field :user %>
  <% end %>

  <!-- Tabla de elementos agregados hasta ahora-->
  <% if @list_pre_registers.length > 0 %>
    <table class="paginated_table sorted_table">
      <thead>

      <tr>

        <br></br>
        <th>Nombre</th>
        <th>Grupo</th>
        <th>Periodo</th>
        <th>Tipologia</th>
        <th>Propietario</th>
        <th>Autor</th>
        <th>Acciones</th>
      </tr>
     </thead>

      <% index = 0 %>
      <% @list_pre_registers.each do |pre_register| %>
        <tr>
          <td><%= pre_register.name %></td>
          <td><%= pre_register.str_group %></td>
          <td><%= pre_register.str_period %></td>
          <td><%= pre_register.str_tipology %></td>
          <td><%= pre_register.str_owner %></td>
          <td><%= pre_register.str_author %></td>
          <td><a href="#" class="js_delete_pre_pregister" pre_register_id="<%= index %>">Eliminar</a></td>
          <% index = index + 1 %>
        </tr>
      <% end %>
    </table>
  <% else %>
    <p></p>
    <br/>
  <% end %>

  <!-- Vamos colocando los pre-register que hemos ido agregando hasta ahora: Step2-->
  <% index = 0 %>
  
  <% @list_pre_registers.each do |pre_register| %>
    <%= fields_for 'list_pre_registers[]', pre_register do |pre_registers_form| %>
      <span id="pre_register_attrs_<%= index %>">
       
        <%= pre_registers_form.hidden_field :preRegisterRegistrationCode %>
        <%= pre_registers_form.hidden_field :name %>
        <%= pre_registers_form.hidden_field :description %>
        <%= pre_registers_form.hidden_field :foundInId %>
        <%= pre_registers_form.hidden_field :height %>
        <%= pre_registers_form.hidden_field :long %>
        <%= pre_registers_form.hidden_field :width %>
        <%= pre_registers_form.hidden_field :weight %>
        <%= pre_registers_form.hidden_field :state %>
        <%= pre_registers_form.hidden_field :group %>
        <%= pre_registers_form.hidden_field :subGroup %>
        <%= pre_registers_form.hidden_field :tipology %>
        <%= pre_registers_form.hidden_field :typeCulturalInstitution %>
        <%= pre_registers_form.hidden_field :culturalInstitution %>
        <%= pre_registers_form.hidden_field :period %>
        <%= pre_registers_form.hidden_field :culture %>
        <%= pre_registers_form.hidden_field :style %>
        <%= pre_registers_form.hidden_field :owner %>
        <%= pre_registers_form.hidden_field :author %>
        <%= pre_registers_form.hidden_field :conservationalState %>
        <%= pre_registers_form.hidden_field :integrityState %>
        <%= pre_registers_form.hidden_field :avatar_file_name %>
        <%= pre_registers_form.hidden_field :avatar_content_type %>
        <%#= pre_registers_form.hidden_field :avatar_file_size %>
        <%= pre_registers_form.hidden_field :shape %>
        <%= pre_registers_form.hidden_field :technique %>
        <%= pre_registers_form.hidden_field :topic %>
        <% index = index + 1 %>
        

      </span>
    <% end %>
  <% end %>

<div class="shadow">
  <fieldset id="agrupacion" >
    <legend>Tipo de Pre Registro</legend>
      <fieldset class="column-left" >
         <div class="field" id="cultural_heritage_cultural_heritage_pre_register_group">
             <%#*<p class="two-col"><label>Grupo (*)</label><%= select_tag "search_complaint_group", options_for_select(@cultural_heritage_groups.collect {|t| [t.name, t.id]}),:onchange => "selectChance( this.options[this.selectedIndex].value)", :include_blank=>"Seleccione" %>
         <%#*</p>%>
         <%= f.select :group,@cultural_heritage_groups.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"},{:onchange => "selectChance( this.options[this.selectedIndex].value)"} %>

         </div>
          </fieldset>
    </fieldset>
</div>
  <%#*<div id="form_ch_inmueble" style="display:none;">%>
   <%#*<div id="form_ch_inmueble" style="display:none;">%>
    <%#*<p>Inmubles</p>%>


    <div class="shadow">
     <fieldset id="agrupacion" >


       <legend>Datos Básicos</legend>
              <fieldset class="column-left" >
                                     <%#*<div class="field">%>
                                      <%#*<label>Código de Registro Nacional:</label>%>
                                      <%#= f.text_field :nationalRegistrationCode %>
                                      <%#*</div>%>
                            <div class="field">
                              <label>Nombre:</label>
                               <%= f.text_field :name %>
                            </div>
                             <div class="field">
                               <label>Descripción:</label>
                              <%= f.text_area :description %>
                            </div>
              </fieldset>

        <fieldset class="column-right"id="agrupacion" >


          <legend>Foto</legend>
          <div class="field">
             <label>Imagen</label><br />
            <%= f.file_field :avatar %>
              </div>
        </fieldset>
    </fieldset>
      <br />


   <fieldset id="agrupacion">
          <legend>Medidas</legend>
          <fieldset class="column-left">
                <div class="field">
                  <label>Alto:</label>
                    <%= f.text_field :height %> m
                </div>
                <div class="field">
                  <label>Largo:</label>
                    <%= f.text_field :long %> m
                </div>
          </fieldset>
          <fieldset class="column-right">
              <div class="field">
                <label>Ancho:</label>
                  <%= f.text_field :width %> m
              </div>
              <div class="field" id="weight" >
                <label>Peso</label>
                  <%= f.text_field :weight %> kg
              </div>
          </fieldset>
  </fieldset>
  <br />

  <fieldset id="agrupacion">
              <legend> Manejo de Estados</legend>
                   <div class="field">
          <label>Estado de conservacion</label><br />
              <%= f.select :conservationalState,@cultural_heritage_conservational_states.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
            </div>
            <div class="field">
          <label>Estado de Integridad</label><br />
              <%= f.select :integrityState,@cultural_heritage_integrity_states.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
            </div>
               
  </fieldset>
  <br />

     <fieldset  id="agrupacion">
       <legend> Agrupaciones </legend>
         <fieldset class="column-left">
        <p><label>Subgrupo(*):</label><%= f.select :subGroup,@cultural_heritage_subgroups.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"} %> </p>
        <input value="1" id="heritage_group" type="hidden" />
        <div id="tipology">
          <%= render :partial=>"tipology"%>
        </div>
        <p><label>Tipo de Institución Cultural(*):</label><%= f.select :typeCulturalInstitution,@cultural_heritage_type_cultural_institutions.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"} %> </p>
      </fieldset>
        <fieldset class="column-right">
        <div id="cultu_insti_type">
          <%= render :partial=>"insti_cultu" %>
        </div>
        <div id="period">
          <%= render :partial=>"period" %>
        </div>
        <div id="culture">
          <%= render :partial=>"culture" %>
        </div>
        <p><label>Estilo:</label><%= f.select :style,@cultural_heritage_styles.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"} %> </p>
      </fieldset>



       <fieldset class="column-left">
              <%#*<div>%>
              <%#*<label>Sub Grupo (*)</label><br />%>
                <%#= f.select :subGroup, @cultural_heritage_subgroups.collect {|t| [t.name,t.id]}, {:include_blank=>"Seleccione"} %>
                  <%#*</div>%>
                  <%#*<div class="field">%>
                 <%#*<label>Tipologia (*)</label><br />%>
                    <%#= f.select :tipology,@cultural_heritage_tipologies.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
                  <%#*</div>%>
                  <%#*<div class="field">%>
                    <%#*<label>Tipo de Institucion Cultural(*)</label><br />%>
                    <%#= f.select :typeCulturalInstitution,@cultural_heritage_type_cultural_institutions.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
                  <%#*</div>%>
           <%#*<div class="field">%>
              <%#*<label>Institucion Cultural (*)</label><br />%>
              <%#= f.select :culturalInstitution,@lista_instituciones.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
            <%#*</div>%>
           
          <div <%if @cultural_heritage_pre_register.subGroup != 1 %>style="display:none"<%end%> id="cultura">
          <p><label>Cultura:</label><%= f.select :culture,@cultural_heritage_cultures.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"},{:class => 'combobox'} %> </p>
        </div>
       </fieldset>

      <%#*<fieldset class="column-right">%>
            <%#*<div class="field">%>
             <%#*<label>Periodo(*)</label><br />%>
              <%#= f.select :period,@cultural_heritage_periods.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
            <%#*</div>%>

           <%#*<div id="culture" class="cult">%>
              <%#*<label>Cultura(*)</label><br />%>
           <%#= f.select :culture,@cultural_heritage_cultures.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
       
           <%#*</div>%>
        
            <%#*<div class="field">%>
           <%#*<label>Estilo (*)</label><br />%>
              <%#= f.select :style,@cultural_heritage_styles.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
            <%#*</div>%>
         <%#*</fieldset>%>
        </fieldset>
  <br />
  <fieldset id="agrupacion">
          <legend>Autores</legend>
           <%#*<div class="field">%>
         <%#*<label>Dueño (*)</label><br />%>
          <%#= f.text_field :owner %>
        <%#*</div>%>

          <p><label id="cultural_heritage_cultural_heritage_pre_register_owner">Dueño:</label><%= f.select :owner,@people.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"},{:class => 'combobox'} %> </p>
          <p><label id="cultural_heritage_cultural_heritage_pre_register_author">Autor:</label><%= f.select :author,@people.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"},{:class => 'combobox'}%> </p>
<%#*<div class="field">%>
          <%#*<label> Autor (*)</label><br />%>
          <%#= f.text_field :author %>
        <%#*</div>%>
            
  </fieldset>
  <br />
  <fieldset id="agrupacion">
      <legend>Datos Adicionales</legend>
      <fieldset class="column-right" >
         <label>Forma:</label><br />
          <%= f.select :shape,@cultural_heritage_shapes.collect {|t| [t.name,t.id]},{:include_blank=>"Seleccione"} %>
      </fieldset>
      <fieldset class="column-left" >
        <div class="field">
          <label>Materiales:</label><br />
            <%= f.text_area :materials %>
        </div>
      </fieldset>
  </fieldset>
  <br />
  <fieldset id="agrupacion">
   
    <legend>Ubicación o Lugar de Hallazgo</legend>
   
    
    <fieldset class="column-left">
    <div class="field">
      <label>Latitud:</label>
       <%= f.text_field :latitude %>
    </div>
    <div class="field">
      <label>Altitud:</label>
      <%= f.text_field :longitude %>
    </div>
    </fieldset>
    <%#*<div id="ub_inmueble">%>
    <fieldset class="column-right">

    <div class="field" id="ub_inmueble">
        <label>Dirección:</label>
        <%= f.text_area :address %>
    </div>

    </fieldset>
   
  </fieldset>
  <br />

     </div>
  <%#*</div>%>



<script language="JavaScript">
<!--
function selectChance(val) {

   <%#*selIdx = document.forms[0].marsupials.selectedIndex;%>
   <%#*newSel = document.forms[0].marsupials.options[selIdx].text;%>
   <%#*alert("Selection has changed to: " + newSel);%>

    if (val== 1)
      {
        <%#*si es inmueble%>
        <%#*var el1 = document.getElementById("weight");%>
        <%#*el1.style.display = 'none';%>
        var el2 = document.getElementById("weight");
        el2.style.display = '';

        <%#*var el3 = document.getElementById("ub_inmueble");%>
        <%#*el3.style.display = '';%>
        var el4 = document.getElementById("ub_inmueble");
        el4.style.display = 'none';


       <%#*alert("Selection has changed to  entro1: " + val);%>
    

      }
   
    else
      {
        <%#*var el1 = document.getElementById("weight");%>
        <%#*el1.style.display = '';%>
        var el2 = document.getElementById("weight");
        el2.style.display = 'none';
        <%#*var el3 = document.getElementById("ub_inmueble");%>
        <%#*el3.style.display = 'none';%>
        var el4 = document.getElementById("ub_inmueble");
        el4.style.display = '';


         <%#*alert("Selection has changed to  entro2: " + val);%>

      }

}
//-->
</script>
 
  
  <div class="actions">
    <%= submit_tag('Guardar Otro') %>
    <%= submit_tag('Finalizar') %>
  </div>
<% end %>

<% if @cultural_heritage_pre_register_request.id.to_i > 0 %>
  <%= link_to 'Regresar', {:controller=>"cultural_heritage/pre_register_requests", :action=>"edit", :id=>@cultural_heritage_pre_register_request.id} %>
<% else %>
  <%= link_to 'Regresar', {:controller=>"cultural_heritage/pre_register_requests", :action=>"new", :cultural_heritage_pre_register_request=>@cultural_heritage_pre_register_request.attributes} %>
<% end %>



<script type="text/javascript">
 // form validation function //
 function validate(form) {

   var group = form.cultural_heritage_cultural_heritage_pre_register_group.value;
   var name = form.cultural_heritage_cultural_heritage_pre_register_name.value;
   var description = form.cultural_heritage_cultural_heritage_pre_register_description.value;
   
   var _height  = form.cultural_heritage_cultural_heritage_pre_register_height.value;
   var _long  = form.cultural_heritage_cultural_heritage_pre_register_long.value;
   var _width  = form.cultural_heritage_cultural_heritage_pre_register_width.value;
   var _weight  = form.cultural_heritage_cultural_heritage_pre_register_weight.value;

   var conservationalState = form.cultural_heritage_cultural_heritage_pre_register_conservationalState.value;
   var integrityState = form.cultural_heritage_cultural_heritage_pre_register_integrityState.value;

   var subGroup = form.cultural_heritage_cultural_heritage_pre_register_subGroup.value;
   var tipology = form.cultural_heritage_cultural_heritage_pre_register_tipology.value;
   var typeCulturalInstitution = form.cultural_heritage_cultural_heritage_pre_register_typeCulturalInstitution.value;
   var culturalInstitution = form.cultural_heritage_cultural_heritage_pre_register_culturalInstitution.value;
   var period = form.cultural_heritage_cultural_heritage_pre_register_period.value;
   var style = form.cultural_heritage_cultural_heritage_pre_register_style.value;
    var culture = form.cultural_heritage_cultural_heritage_pre_register_style.culture;

   var owner = form.cultural_heritage_cultural_heritage_pre_register_owner.value;
   var author = form.cultural_heritage_cultural_heritage_pre_register_author.value;

   //Validaciones
if(culture  == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_culture','Debe seleccionar una institución.',3);
     return false;
    }
    if(name == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_name','Debe ingresar un nombre .',3);
     return false;
    }
    if(!name.match(nameRegex)) {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_name','Debe de ingresar un nombre válido.',3);
     return false;
    }
    if(description == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_description','Debe ingresar una decripción para la colección.',3);
     return false;
    }
    if(description.match(messageRegex)) {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_description','Debe ingresar una decripción válida.',3);
     return false;
    }

    if(parseFloat(_height) <= 0) {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_height','Debe ingresar una dimensión válida.',3);
     return false;
    }
    if(parseFloat(_long) <= 0) {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_height','Debe ingresar una dimensión válida.',3);
     return false;
    }
    if(parseFloat(_width) <= 0) {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_width','Debe ingresar una dimensión válida.',3);
     return false;
    }
    if(parseFloat(_weight) <= 0) {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_height','Debe ingresar una dimensión válida.',3);
     return false;
    }

    if(conservationalState  == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_conservationalState','Debe seleccionar estado de conservacion.',3);
     return false;
    }
    if(integrityState  == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_integrityState','Debe seleccionar estado de integridad.',3);
     return false;
    }

    if(subGroup  == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_subGroup','Debe seleccionar un subgrupo.',3);
     return false;
    }
    if(tipology  == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_tipology','Debe seleccionar una tipología.',3);
     return false;
    }
    if(typeCulturalInstitution  == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_typeCulturalInstitution','Debe seleccionar un tipo de institución cultural.',3);
     return false;
    }
    if(culturalInstitution  == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_culturalInstitution','Debe seleccionar una institución.',3);
     return false;
    }
    if(period  == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_period','Debe seleccionar un período.',3);
     return false;
    }
    <%#*if(style  == "") {%>
     <%#*inlineMsg('cultural_heritage_cultural_heritage_pre_register_style','Debe seleccionar un estilo.',3);%>
     <%#*return false;%>
    <%#*}%>

    if(author == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_author','Debe ingresar un autor .',3);
     return false;
    }
    if(owner == "") {
     inlineMsg('cultural_heritage_cultural_heritage_pre_register_owner','Debe seleccionar un propietario para la colección.',3);
     return false;
    }

 }
 </script>
